#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 5e4 + 10;
typedef long long LL;
int n;
struct node
{
	LL s, w;
}a[N];
bool cmp(node& i, node& j)
{
	return i.w + i.s < j.w + j.s;
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i].w >> a[i].s;
	sort(a + 1, a + 1 + n, cmp);
	LL ret = -1e9 - 10, w = 0;
	for (int i = 1; i <= n; i++)
	{
		ret = max(ret, w - a[i].s);
		w += a[i].w;
	}
	cout << ret << endl;
	return 0;
}

